﻿<%@ Page Language="C#" MasterPageFile="~/Addmin/BackEnd/MTP_Admin.Master" AutoEventWireup="true"
    CodeBehind="MG_Products.aspx.cs" Inherits="Bussiness.View.BackEnd.MG_Products" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <ext:Panel ID="Panel2" runat="server" Title="Quản lý sản phẩm" PaddingSummary="10px 5px 5px 5px">
        <Items>
            <ext:FieldSet ID="FieldSet1" runat="server" Layout="ColumnLayout" Title="Thông tin tìm kiếm"
                PaddingSummary="10px 5px 0 5px" Height="140">
                <Items>
                    <ext:Container ID="Container2" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:TextField ID="tk_maHang" runat="server" FieldLabel="Mã hàng" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                        <Items>
                            <ext:TextField ID="tk_tenHH" runat="server" FieldLabel="Tên hàng hóa" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                        <Items>
                            <ext:TextField ID="tk_soLuong" runat="server" FieldLabel="Số lượng" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                    </ext:Container>
                    <ext:Container ID="Container3" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:DateField runat="server" ID="tk_NgayNhap" IDMode="Static" FieldLabel="Ngày Nhập"
                                AnchorHorizontal="100%" />
                        </Items>
                        <Items>
                            <ext:SelectBox ID="LoaiSP_Grid" runat="server" FieldLabel="Loại sản phẩm" AnchorHorizontal="100%"
                                DataIndex="Status" IDMode="Static" ValueField="ID" DisplayField="Name">
                                <Store>
                                    <ext:Store ID="LoaiSP_Store" runat="server">
                                        <Reader>
                                            <ext:ArrayReader IDProperty="ID">
                                                <Fields>
                                                    <ext:RecordField Name="ID" Type="int" Mapping="ID" />
                                                    <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                                </Fields>
                                            </ext:ArrayReader>
                                        </Reader>
                                    </ext:Store>
                                </Store>
                            </ext:SelectBox>
                        </Items>
                        <Items>
                            <ext:Checkbox ID="tk_sale" IDMode="Static"  runat="server" FieldLabel="Giảm giá"/>
                            <ext:Button ID="Button3" runat="server" Text="Tìm kiếm" FieldLabel=" " LabelSeparator=" "
                                Icon="Find">
                                <DirectEvents>
                                    <Click OnEvent="search_Product">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Container>
                </Items>
            </ext:FieldSet>
        </Items>
        <Items>
            <ext:GridPanel ID="DSHangHoa_Grid" IDMode="Static" runat="server" Height="300" AutoScroll="true"
                Region="Center">
                <Store>
                    <ext:Store ID="DSHangHoa_Store" runat="server" AutoDataBind="true" SkipIdForNewRecords="false">
                        <Reader>
                            <ext:JsonReader IDProperty="ID">
                                <Fields>
                                    <ext:RecordField Name="ID" Type="String" Mapping="ID" />
                                    <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                    <ext:RecordField Name="Code" Type="String" Mapping="Code" />
                                    <ext:RecordField Name="Unit" Type="String" Mapping="Unit" />
                                    <ext:RecordField Name="Count" Type="Int" Mapping="Count" />
                                    <ext:RecordField Name="PriceImport" Type="Int" Mapping="PriceImport" />
                                    <ext:RecordField Name="PriceExprort" Type="Int" Mapping="PriceExprort" />
                                    <ext:RecordField Name="DateImport" Type="Date" Mapping="DateImport" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel2" runat="server" AutoDataBind="true">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="ID" Header="Mã" DataIndex="ID" Hidden="true" />
                        <ext:Column Header="Mã hàng" DataIndex="Code" AutoDataBind="true" Width="70" MenuDisabled="True" />
                        <ext:Column Header="Tên" DataIndex="Name" AutoDataBind="true" Width="150" />
                        <ext:Column Header="Đơn vị tính" DataIndex="Unit" AutoDataBind="true" Width="90"
                            MenuDisabled="True" />
                        <ext:Column Header="Số lượng" DataIndex="Count" AutoDataBind="true" 
                            MenuDisabled="True" Align ="Right"/>
                        <ext:NumberColumn Header="Gía nhập" DataIndex="PriceImport" AutoDataBind="true" MenuDisabled="True"
                            Format="0,00" Align ="Right" />
                        <ext:NumberColumn Header="Gía bán" DataIndex="PriceExprort" AutoDataBind="true" MenuDisabled="True"
                            Format="0,00" Align ="Right"/>
                        <ext:DateColumn Header="Ngày cập nhật" DataIndex="DateImport" AutoDataBind="true"
                            MenuDisabled="True" Format="dd/MM/yyyy" Align ="Center"/>
                        <ext:CommandColumn Header="Action">
                            <Commands>
                                <ext:GridCommand Icon="Delete" CommandName="Delete" ToolTip-Text="Xóa">
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                                <ext:GridCommand Icon="NoteEdit" CommandName="Edit" ToolTip-Text="Sửa/Xem" />
                            </Commands>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="20" StoreID="DSHangHoa_Store"
                        DisplayInfo="false" />
                </BottomBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" ID="RowSelectionModel1">
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <Command Handler="detail(command, record.data.ID)" />
                </Listeners>
            </ext:GridPanel>
        </Items>
        <Buttons>
            <ext:Button runat="server" Text="Thêm" ID="them" Icon="Add">
                <Listeners>
                    <Click Fn="showDetail" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Panel>

    <script type="text/javascript">

        var showResult = function(btn) {
        };
        function detail(command, id) {
            if (command == 'Delete') {
                Ext.MessageBox.confirm('Chú ý', 'Bạn có muốn xóa Sản Phẩm này không?',
        function(btn) {
            if (btn == 'yes') {
                Ext.net.DirectMethod.request({
                    url: "MG_Products.aspx",
                    cleanRequest: true,
                    params: {
                        Action: command,
                        ID: id
                    }
               });
              
            }
            else {
                return false;
            }

        });

            } else {
                window.location = "Product_Detail.aspx?Action=" + command + "&ID=" + id;

            }

        }



        function AddProperty() {
            var grid = Ext.getCmp('pu_sizeSL_Grid');
            grid.getRowEditor().stopEditing();
            var numOfRow = grid.getStore().getCount();
            grid.insertRecord(numOfRow);
            grid.getView().refresh();
            grid.getView().focusRow(numOfRow);
            grid.getSelectionModel().selectRow(numOfRow);
            grid.getRowEditor().startEditing(numOfRow);
        }




        //tu dong xoa dung khi du lieu tren Grid Null
        var DeleteRow = function() {
            var store = Ext.getCmp('pu_sizeSL_Grid').getStore();
            var index = 0;
            store.each(function(record) {
                if (record.data['Size'] == "" || record.data['Amount'] == "") {

                    store.removeAt(index);
                }
                index = index + 1;
            }
)
        };
        function showDetail() {
            window.location = "Product_Detail.aspx";
        }
    </script>

</asp:Content>
